requirejs.config({
    baseUrl: '../js/libs',
    paths: {
        jquery: 'jquery.min',
        jquery_route: 'jquery.route',
        bootstrap: "../../bootstrap-3.3.5/dist/js/bootstrap.min",
        bootstrap_paginator:"../plugins/bootstrap-paginator/bootstrap-paginator",
        config: "../common/config",
        pageJs: '../common/pageJs',
        common:'../common/common',
        arttemplateUtil: '../js/common/arttemplate-util',
        validform:"../plugins/Validform/Validform_v5.3.2"
    },
    shim: { //引入没有使用requirejs模块写法的类库。backbone依赖underscore
        'jquery': {
            exports: '$'
        },
        'bootstrap':['jquery'],
        'bootstrap_paginator':{
        	deps:['bootstrap'],
        	exports: 'bootstrp'
        },
        //'bootstrap_paginator':['bootstrap'],
        //'pageJs':['bootstrap_paginator'],
        'validform':['jquery']
    }
});
requirejs(['jquery', 'pageJs','config', 'arttemplateUtil','common','validform'], 
		function($, pageJs,config, arttemplateUtil,common) {
	var param = {};
	var initData = function(){
		common.loading();
		common.common_ajax_request('/api/v1/queryDeliverPrevueContent',param,false,function(data,code,msg){
			//console.info(JSON.stringify(data));
			setData(data);
			pageJs.setPage(data.pageNo,data.totalPage,data.totalCount,callback);
			initBtn();
			layer.closeAll('loading'); //关闭加载层
		},"","post");
	};
	var noticelist_tpl;//
	var initTpl = function(){
		noticelist_tpl = arttemplateUtil.template.compile($.setHTML('sidedishes/templates/notice_tpl.html'));
	};
	//
	var setData = function(data){
		var tempList = data.records;
		var res = {
			records:tempList,
			url:config.imgRoot()
		};
		$("#noticelist").html(noticelist_tpl(res));
	};
	
	var callback = function(page){
		param.pageNo=page;
		initData();
	};
	
	var initBtn = function(){
		$(".st-edit-btn").click(function(){
			var id = $(this).attr("data-id");
			window.location.href="#sidedishes/noticeadd/"+id;
		});
		$(".st-del-btn").click(function(){
			////$("#deleteModal").modal('show');
			var id = $(this).attr("data-id");
			var name = $(this).attr("data-name");
			layer.confirm('确定删除吗？', {
				  btn: ['确定','取消']
			}, function(){
				common.loading();
				var param = {id: id, name: name};
				common.common_ajax_request('/api/v1/deliver_prevue_content_del',param,false,function(data,code,msg){
					if(code==200 && msg.businessCode==0){
						if(data.businessCode == 100117){
							layer.closeAll();
							$("#deleteModal").modal('show');
						}else{
							layer.alert("删除成功！");
							initData();
						}
					}else{
						layer.alert(data.businessNote);
					}
				},"","post");
			}, function(){});
		});
	};
	
	var init = function() {
		initTpl();
		initData();
	};
	
	init();
});
